﻿using Core.SimpleTemp.Common;
using Core.SimpleTemp.Entitys;
using Core.Toolkit.DbInitializer;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core.SimpleTemp.Repositories.CBS
{
    /// <summary>
    /// 承包商数据初始化
    /// </summary>
    public class PX_DBinit : DbInitializer
    {
        public PX_DBinit()
        {
            Sort = 1;
        }
        public override void Initialize(DbContext context, WebAppOptions _webAppOptions)
        {
            var adminUser = context.Set<SysUser>().Where(a => a.LoginName == _webAppOptions.AdminLoginName).FirstOrDefault();
            //培训记录
            List<PX_Plan> PX_PlanList = new List<PX_Plan>();
            for (int i = 0; i < 10; i++)
            {
                PX_PlanList.Add(new PX_Plan()
                //context.Set<PX_Plan>().Add(new PX_Plan()
                {
                    Nameoftrainingplan = "培训计划名称" + i,
                    Trainingmethods = new Random().Next(0, 1).ToString(),//培训类型
                    State = new Random().Next(0, 1).ToString(),//培训状态
                    Trainingcontent = "培训内容" + i,
                    Target = "目标" + i,
                    Trainingvenues = "中潭路100#204-1403" + i,
                    TrainingBeginTime = DbInitializerHelp.GetRandomDate()//开始日期
                });
            }
            context.Set<PX_Plan>().AddRange(PX_PlanList);

            //培训类别
            List<PX_CourseClass> CourseClassList = new List<PX_CourseClass>();
            for (int i = 0; i < 10; i++)
            {
                CourseClassList.Add(new PX_CourseClass()
                {
                    Name = "培训类别名" + i,
                    Id = Guid.NewGuid()
                });
            }
            context.Set<PX_CourseClass>().AddRange(CourseClassList);



            List<PX_Course> PX_CourseList = new List<PX_Course>();

            //培训记录
            for (int i = 0; i < 10; i++)
            {
                PX_CourseList.Add(new PX_Course()
                {
                    CoursewareName = "课程名称" + i,
                    Learningtime = new Random().Next(40, 90),//学时
                    CourseAttachment = Guid.NewGuid(),//附件
                    ClassificationofCourseware = CourseClassList[new Random().Next(0, 9)].Id,//课程分类ID
                    //培训老师
                    PX_CourseTeacher = new PX_CourseTeacher()
                    {
                        Teacher = adminUser.Id
                    },
                    CreateTime = DateTime.Now
                });
            }
            context.Set<PX_Course>().AddRange(PX_CourseList);

            ////考題
            //List<PX_Questions> PX_QuestionsList = new List<PX_Questions>();
            //for (int i = 0; i < 100; i++)
            //{
            //    PX_QuestionsList.Add(new PX_Questions()
            //    {
            //        trainingcourse = PX_PlanList[new Random().Next(0, 2)].Id,
            //        QuestionManagementContent = "题目名称" + i,
            //        PX_QuestionsOptions = new List<PX_QuestionsOptions>() {
            //            new PX_QuestionsOptions(){
            //                 OptionName="A",
            //                 OptionComment="选项内容A",
            //                 IsAnswer="0"
            //            },
            //            new PX_QuestionsOptions(){
            //                 OptionName="B",
            //                 OptionComment="选项内容B",
            //                 IsAnswer="0"
            //            },
            //            new PX_QuestionsOptions(){
            //                 OptionName="C",
            //                 OptionComment="选项内容C",
            //                 IsAnswer="1"
            //            }
            //        }
            //    }); ;
            //}
            //context.Set<PX_Questions>().AddRange(PX_QuestionsList);



            ////考试管理
            //List<PX_Exam> pX_ExamList = new List<PX_Exam>();
            //for (int i = 0; i < 10; i++)
            //{
            //    pX_ExamList.Add(new PX_Exam()
            //    {
            //        PX_Plan = PX_PlanList[new Random().Next(0, 2)],
            //        Fullmarks = new Random().Next(90, 100),
            //        PX_ExamUser = new List<PX_ExamUser>() {
            //             new  PX_ExamUser(){
            //                  PersonID=adminUser.Id,
            //                   Examinationscore=new Random().Next(80, 90)
            //             }
            //        },
            //        Examinationstarttime = DbInitializerHelp.GetRandomDate(),
            //        Endtimeofexamination = DbInitializerHelp.GetRandomDate(),
            //        Status = new Random().Next(0, 2).ToString()
            //        //PX_Questions = PX_QuestionsList
            //    });
            //}
            //context.Set<PX_Exam>().AddRange(pX_ExamList);

            context.SaveChanges();
        }
    }
}
